package com.uni.dto;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.uni.common.entity.ShopCommoditySpecification;
import com.uni.common.util.SystemConfig;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 店铺商品
 * @author yuyanzheng
 *
 */
@NoArgsConstructor
@Data
public class ShopCommodityDTO {
	private Long id;
	private Long shopId;
	private Long commodityCategoryId;
	private String coverUrl;
	private String imageUrls;
	private String name;
	private Integer price;
	private Integer specification;
	private Integer status;
	private Date updateTime;
	private Date createTime;
	
	private Integer number;
	
	private int cartNumber;
	
	private List<ShopCommoditySpecification> specifications;
	
	private List<ShopCommodityFieldDTO> fields;
	
	public String getCoverUrlAll() {
		if(StringUtils.isNotBlank(coverUrl) && !coverUrl.startsWith("http")) {
			return SystemConfig.basePath + coverUrl;
		}
		return coverUrl;
	}
	
	public List<String> getImageUrlAll() {
		List<String> imgs = new ArrayList<String>();
		imgs.add(this.getCoverUrlAll());
		if(StringUtils.isNotBlank(imageUrls)) {
			for(String img : imageUrls.split(",")) {
				if(StringUtils.isNotBlank(img) && !img.startsWith("http")) {
					imgs.add(SystemConfig.basePath + img);
				} else {
					imgs.add(img);
				}
			}
		}
		return imgs;
	}
}
